package main

import (
	"encoding/json"
	"log"
	"yk3.19/config"
	"yk3.19/global"
	"yk3.19/inits"
	"yk3.19/internal/model"
	"yk3.19/internal/queue"
)

func main() {
	config.Init()
	inits.MysqlConfig()
	inits.InitRabbitMq()

	msgs := queue.PublishSub("notification")

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)
			var chat model.Chat
			json.Unmarshal(d.Body, &chat)
			global.DB.Create(&chat)
		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
